// pages/employment/employment.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    formItems: [
      { label: '教育背景', field: 'education' },
      { label: '研究经历', field: 'research_experience' },
      { label: '学术成果', field: 'academic_achievements' },
      { label: '实习实践', field: 'internship_experience' },
      { label: '技能证书', field: 'certifications' },
      { label: '个人陈述', field: 'personal_statement' }
    ],
    formData: {},
    resumeUrl: ''
  },
  onInput(e) {
    const field = e.currentTarget.dataset.field;
    this.setData({
      [`formData.${field}`]: e.detail.value
    });
  },
  generateResume() {
    // 存储到全局数据
    getApp().globalData.resumeData = this.data.formData;
    // 跳转模板选择页
    wx.navigateTo({
      url: '/pages/employ-templates/employ-templates'
    });
  },
  // 获取字段标签
  getFieldLabel(field) {
    return this.data.formItems.find(item => item.field === field)?.label || '';
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  navigateToEdit(e) {
    const field = e.currentTarget.dataset.field;
    wx.navigateTo({
      url: `/pages/resume_edit/resume_edit?field=${field}`
    })
  },
  uploadImage() {
    wx.chooseMedia({
      count: 1,
      mediaType: ['image'],
      success: (res) => {
        this.setData({
          resumeUrl: res.tempFiles[0].tempFilePath
        });
        // 图片选择完成后再显示加载状态
        wx.showLoading({
          title: '上传中...',
          mask: true
        });
        setTimeout(() => {
          wx.hideLoading();
          wx.showToast({
            title: '上传失败',
            icon: 'none'
          });
        }, 1500);
      },
      fail: (err) => {
        wx.showToast({
          title: '上传失败',
          icon: 'none'
        });
        console.error('上传失败:', err);
      }
    })
  }
})